<?php
/**
 * Created by PhpStorm.
 * User: zhengze
 * Date: 2019/7/1
 * Time: 18:29
 */

namespace app\api\validate;

use app\api\enum\ScopeEnum;
use app\api\service\Token;
use common\traits\InstanceTrait;
use common\exception\ExceptionEmun;
use app\lib\exception\TokenException;

/**
 * Class MemberValidate
 * 验证类的基类
 */
class MemberValidate extends BaseValidate
{
    use InstanceTrait;
    /**
     * 验证场景值  通过这个可以验证不同的场景
     * @var array
     */
    protected $scene = [
        'loginVerify' => ['phone', 'password'],
        'register' => ['phone', 'password','member_name'],
    ];

    /**
     * 定义验证规则
     * 格式：'字段名|字段中文名'    =>    ['规则1','规则2'...]
     * @var array
     */
    protected $rule = [
        'phone|手机号' => ['require', 'isMobile', 'isPositiveInteger'],
        'password|密码' => ['require', 'length:6,20'],
        'member_name|会员名' => ['require', 'unique:member', 'length:2,12'],
    ];

    /**
     * 处理RegisterVerify场景
     */
    public function sceneRegister()
    {
        $add_rule = [
            'phone' => 'unique:member'
        ];
        $this->addRule($add_rule);
    }


}